// PeerLocal represents a pair peer connection
package peer

import (
	"log"
	"sync"
)


type SessionLocal struct {
	id             string
	mu             sync.RWMutex
	config         WebRTCTransportConfig
	peers          map[string]Peer
	relayPeers     map[string]*RelayPeer
	closed         atomicBool
	audioObs       *AudioObserver
	fanOutDCs      []string
	datachannels   []*Datachannel
	onCloseHandler func()
}

type PeerLocal struct {
	sync.Mutex
	id string
	// closed   atomicBool
	// session  Session
	// provider SessionProvider

	// publisher  *Publisher
	// subscriber *Subscriber
	VideoSourceID string
}

// NewPeer creates a new PeerLocal for signaling with the given SFU
func NewPeer(provider SessionProvider) *PeerLocal {
	log.SetFlags(log.Ldate | log.Lshortfile)
	return &PeerLocal{}
}

// NewSession creates a new SessionLocal
func NewSession(id string, dcs []*Datachannel, cfg WebRTCTransportConfig) Session {
	s := &SessionLocal{
		id:           id,
		peers:        make(map[string]Peer),
		relayPeers:   make(map[string]*RelayPeer),
		datachannels: dcs,
		config:       cfg,
		audioObs:     NewAudioObserver(cfg.Router.AudioLevelThreshold, cfg.Router.AudioLevelInterval, cfg.Router.AudioLevelFilter),
	}
	log1.SetFlags(log1.Ldate | log1.Lshortfile | log1.Ltime)
	go s.audioLevelObserver(cfg.Router.AudioLevelInterval)
	return s
}